home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / manual-p / man_db-2.000 / man_db-2 / man_db-2.3.10 / lib / strappend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-17  |  2.0 KB  |  79 lines

  1. /* strappend.c -- append to a dynamically allocated string
  2.    Copyright (C) 1994 Markus Armbruster
  3.  
  4.    This program is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU General Library Public License
  6.    as published by the Free Software Foundation; either version 2, or
  7.    (at your option) any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; see the file COPYING.LIB.  If not, write
  16.    to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  17.    02139, USA.  */
  18.  
  19. #ifdef HAVE_CONFIG_H
  20. #  include "config.h"
  21. #endif /* HAVE_CONFIG_H */
  22.  
  23. #if defined(STDC_HEADERS)
  24. #  include <string.h>
  25. #elif defined(HAVE_STRING_H)
  26. #  include <string.h>
  27. #elif defined(HAVE_STRINGS_H)
  28. #  include <strings.h>
  29. #else /* no string(s) header */
  30. extern char *strcpy();
  31. #endif /* STDC_HEADERS */
  32.  
  33. #ifdef __STDC__
  34. #  include <stdarg.h>
  35. #  define VOID         void
  36. #  define VA_START    va_start (ap, str)
  37. #else
  38. #  include <varargs.h>
  39. #  define VOID char
  40. #  define VA_START    va_start (ap)
  41. #endif
  42.  
  43. extern VOID *xrealloc(void *p, size_t n);
  44.  
  45. /* append strings to first argument, which is realloced to the correct size 
  46.    first arg may be NULL */
  47. #ifdef __STDC__
  48. char *strappend (char *str, ...)
  49. #else
  50. char *strappend (str, va_alist)
  51.      char *str;
  52.      va_dcl
  53. #endif
  54. {
  55.       va_list ap;
  56.       int len, newlen;
  57.       char *next, *end;
  58.  
  59.       len = str ? strlen (str) : 0;
  60.  
  61.       VA_START;
  62.       newlen = len + 1;
  63.       while ((next = va_arg (ap, char *)))
  64.               newlen += strlen (next);
  65.       va_end (ap);
  66.  
  67.       str = xrealloc (str, newlen);
  68.       end = str + len;
  69.  
  70.       VA_START;
  71.       while ((next = va_arg (ap, char *))) {
  72.               strcpy (end, next);
  73.               end += strlen (next);
  74.       }
  75.       va_end (ap);
  76.  
  77.       return str;
  78. }
  79.